using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace Yoozoo.Gameplay.City
{
    public class FixedScaleBuilding : MonoBehaviour
    {
        [Serializable]
        public class NodeConfig
        {
            public Transform node;
            public Vector3 lossyScale = Vector3.one;
        }
        
        [SerializeField]
        public List<NodeConfig> nodeCfgs;
        
        // Update is called once per frame
        void Update()
        {
            foreach(var nodeCfg in nodeCfgs)
            {
                if (nodeCfg.node && nodeCfg.lossyScale != nodeCfg.node.lossyScale)
                {
                    Vector3 parentScale = Vector3.one;
                    if (nodeCfg.node.parent)
                    {
                        parentScale = nodeCfg.node.parent.lossyScale;
                    }
                    nodeCfg.node.localScale = new Vector3(nodeCfg.lossyScale.x / parentScale.x, nodeCfg.lossyScale.y / parentScale.y, nodeCfg.lossyScale.z / parentScale.z);
                }
            }
        }
    }
}
